package com.cloudbroker.bcs.platform.dav.middle.service.impl;

import com.cloudbroker.bcs.platform.dav.middle.dao.BrokerVoteDAO;
import com.cloudbroker.bcs.platform.dav.middle.entity.BrokerVote;
import com.cloudbroker.bcs.platform.dav.middle.entityexample.BrokerVoteQueryCondition;
import com.cloudbroker.bcs.platform.dav.middle.entityview.VoteRecordListView;
import com.cloudbroker.bcs.platform.dav.middle.service.BrokerVoteService;
import com.cloudbroker.bcs.platform.dav.middle.service.base.TenantServiceImplBase;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * Created by Thinkpad on 2016/10/26.
 */
@Service
public class BrokerVoteServiceImpl extends TenantServiceImplBase<BrokerVote,Long> implements BrokerVoteService{
    @Resource
    protected BrokerVoteDAO brokerVoteDAO;
    @Override
    protected BrokerVoteDAO getDAO(){return brokerVoteDAO;}

    @Override
    public BrokerVote findByName(String broker_name){
        List<BrokerVote> brokerVotes = brokerVoteDAO.findByName(broker_name);
        if(brokerVotes == null || brokerVotes.size()==0)
        {
            return null;
        }
        return  brokerVotes.get(0);
    }

    @Override
    public List<BrokerVote> findAndSort(String order_by){
        return brokerVoteDAO.findAndSort(order_by);
    }

    @Override
    public void addVoteNum(Long broker_id ,Integer tenant_id,String vote_type,Date create_time) {
        brokerVoteDAO.addVoteNum(broker_id,tenant_id,vote_type,create_time);
    }

    @Override
    public BrokerVote getVoteByBrokerId(Long broker_id ,String vote_type) {
        return brokerVoteDAO.getVoteByBrokerId(broker_id,vote_type);
    }

    @Override
    public List<VoteRecordListView> getVoteRecordList(BrokerVoteQueryCondition condition) {

        return brokerVoteDAO.getVoteRecordList(condition);
    }

    @Override
    public BrokerVote findByBorkerId(Integer tenant_id, Long broker_id,String vote_type) {
        return brokerVoteDAO.findByBorkerId(tenant_id,broker_id,vote_type);
    }

    @Override
    public Date getLastVoteDate(Integer tenantId,String vote_type) {
        return brokerVoteDAO.getLastVoteDate(tenantId,vote_type);
    }
}
